<template>
  <div class="duty-export">
    <!-- 值班信息选择 -->
    <div class="duty-select-section">
      <div class="section-header">
        <i class="el-icon-s-custom"></i>
        <span>选择要导出的值班信息</span>
      </div>
      
      <div class="select-all-box">
        <el-checkbox v-model="selectAll" @change="handleSelectAll">
          全选
        </el-checkbox>
        <span class="select-count">已选择 {{ selectedDuties.length }} 条记录</span>
      </div>

      <div class="duty-list">
        <div 
          v-for="duty in dutyRecords" 
          :key="duty.id"
          class="duty-item"
        >
          <el-checkbox 
            v-model="duty.selected"
          ></el-checkbox>
          <div class="duty-info" @click="toggleDuty(duty.id)">
            <div class="duty-header">
              <span class="duty-name">{{ duty.dutyPerson }}</span>
              <el-tag :type="getStatusType(duty.status)" size="mini">
                {{ duty.status }}
              </el-tag>
            </div>
            <div class="duty-meta">
              <span><i class="el-icon-time"></i>{{ duty.dutyDate }}</span>
              <span><i class="el-icon-s-flag"></i>{{ duty.shift }}</span>
            </div>
            <div class="duty-meta">
              <span><i class="el-icon-location-outline"></i>{{ duty.location }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 导出字段选择 -->
    <div class="field-select-section">
      <div class="section-title">
        <i class="el-icon-s-grid"></i>
        <span>选择导出字段</span>
      </div>
      <div class="field-options">
        <el-checkbox-group v-model="selectedFields">
          <div 
            v-for="field in exportFields" 
            :key="field.value"
            class="field-item"
          >
            <el-checkbox :label="field.value">
              <span class="field-label">
                <i :class="field.icon"></i>
                {{ field.label }}
              </span>
            </el-checkbox>
          </div>
        </el-checkbox-group>
      </div>
    </div>

    <!-- 导出格式选择 -->
    <div class="export-format-section">
      <div class="section-title">
        <i class="el-icon-download"></i>
        <span>选择导出格式</span>
      </div>
      <div class="format-options">
        <div 
          v-for="format in exportFormats" 
          :key="format.type"
          class="format-card"
          :class="{ active: selectedFormat === format.type }"
          @click="selectedFormat = format.type"
        >
          <div class="format-icon" :style="{ backgroundColor: format.color }">
            <i :class="format.icon"></i>
          </div>
          <div class="format-name">{{ format.name }}</div>
          <div class="format-desc">{{ format.description }}</div>
        </div>
      </div>
    </div>

    <!-- 导出选项 -->
    <div class="export-options-section">
      <div class="section-title">
        <i class="el-icon-setting"></i>
        <span>导出选项</span>
      </div>
      <div class="options-list">
        <div class="option-item">
          <div class="option-label">
            <i class="el-icon-picture"></i>
            <span>包含头像照片</span>
          </div>
          <el-switch v-model="exportOptions.includePhoto"></el-switch>
        </div>
        <div class="option-item">
          <div class="option-label">
            <i class="el-icon-phone"></i>
            <span>包含联系方式</span>
          </div>
          <el-switch v-model="exportOptions.includeContact"></el-switch>
        </div>
        <div class="option-item">
          <div class="option-label">
            <i class="el-icon-document"></i>
            <span>包含备注信息</span>
          </div>
          <el-switch v-model="exportOptions.includeRemark"></el-switch>
        </div>
        <div class="option-item">
          <div class="option-label">
            <i class="el-icon-data-line"></i>
            <span>包含统计信息</span>
          </div>
          <el-switch v-model="exportOptions.includeStatistics"></el-switch>
        </div>
      </div>
    </div>

    <!-- 导出历史 -->
    <div class="export-history-section">
      <div class="section-title">
        <i class="el-icon-document-copy"></i>
        <span>最近导出记录</span>
      </div>
      <div class="history-list">
        <div 
          v-for="record in exportHistory" 
          :key="record.id"
          class="history-item"
        >
          <div class="history-icon" :style="{ backgroundColor: getFormatColor(record.format) }">
            <i :class="getFormatIcon(record.format)"></i>
          </div>
          <div class="history-info">
            <div class="history-title">{{ record.fileName }}</div>
            <div class="history-detail">
              <span class="format-name">{{ record.format }}</span>
              <span class="separator">·</span>
              <span class="file-size">{{ record.fileSize }}</span>
              <span class="separator">·</span>
              <span class="export-time">{{ record.exportTime }}</span>
            </div>
          </div>
          <div class="history-action">
            <el-button 
              type="text" 
              size="mini"
              icon="el-icon-download"
              @click="downloadFile(record)"
            >
              下载
            </el-button>
          </div>
        </div>
      </div>
    </div>

    <!-- 导出按钮 -->
    <div class="action-buttons">
      <el-button 
        type="primary" 
        size="large"
        icon="el-icon-download"
        @click="handleExport"
        :disabled="selectedDuties.length === 0 || selectedFields.length === 0"
      >
        导出值班信息（{{ selectedDuties.length }}）
      </el-button>
    </div>

    <!-- 导出确认对话框 -->
    <el-dialog
      title="确认导出"
      :visible.sync="showExportDialog"
      width="90%"
      center
      custom-class="export-dialog"
    >
      <div class="export-confirm-content">
        <div class="confirm-info">
          <i class="el-icon-info"></i>
          <div class="info-text">
            <p>即将导出 <strong>{{ selectedDuties.length }}</strong> 条值班信息</p>
            <p>导出格式：<strong>{{ selectedFormatName }}</strong></p>
            <p>导出字段：<strong>{{ selectedFields.length }}</strong> 个字段</p>
          </div>
        </div>
        <div class="duty-summary">
          <div class="summary-title">包含以下值班信息：</div>
          <div class="summary-list">
            <div 
              v-for="(duty, index) in selectedDutiesList" 
              :key="duty.id"
              class="summary-item"
            >
              <span class="item-index">{{ index + 1 }}.</span>
              <span class="item-title">{{ duty.dutyPerson }} - {{ duty.dutyDate }} {{ duty.shift }}</span>
            </div>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showExportDialog = false">取消</el-button>
        <el-button type="primary" @click="confirmExport">确认导出</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { 
  getDutyRecords,
  exportDutyInfo,
  batchExportDutyInfo,
  getExportHistory
} from './service';

export default {
  name: 'DutyExport',

  data() {
    return {
      dutyRecords: [],
      selectAll: false,
      selectedFormat: 'Excel',
      
      // 导出字段
      exportFields: [
        { value: 'dutyPerson', label: '值班人员', icon: 'el-icon-user' },
        { value: 'dutyDate', label: '值班日期', icon: 'el-icon-date' },
        { value: 'shift', label: '值班班次', icon: 'el-icon-s-flag' },
        { value: 'location', label: '值班地点', icon: 'el-icon-location-outline' },
        { value: 'department', label: '所属部门', icon: 'el-icon-office-building' },
        { value: 'phone', label: '联系电话', icon: 'el-icon-phone' },
        { value: 'emergencyContact', label: '紧急联系人', icon: 'el-icon-phone-outline' },
        { value: 'duties', label: '主要职责', icon: 'el-icon-s-order' },
        { value: 'events', label: '处理事件', icon: 'el-icon-warning' },
        { value: 'remark', label: '备注信息', icon: 'el-icon-document' }
      ],
      selectedFields: ['dutyPerson', 'dutyDate', 'shift', 'location', 'department', 'phone'],
      
      // 导出格式
      exportFormats: [
        {
          type: 'Excel',
          name: 'Excel表格',
          description: '便于数据分析',
          icon: 'el-icon-s-grid',
          color: '#67C23A'
        },
        {
          type: 'PDF',
          name: 'PDF文档',
          description: '便于阅读打印',
          icon: 'el-icon-document',
          color: '#E6A23C'
        },
        {
          type: 'Word',
          name: 'Word文档',
          description: '可编辑格式',
          icon: 'el-icon-edit-outline',
          color: '#409EFF'
        },
        {
          type: 'Text',
          name: '文本文件',
          description: '纯文本格式',
          icon: 'el-icon-tickets',
          color: '#909399'
        }
      ],

      // 导出选项
      exportOptions: {
        includePhoto: false,
        includeContact: true,
        includeRemark: true,
        includeStatistics: false
      },

      // 导出历史
      exportHistory: [],

      // 对话框控制
      showExportDialog: false
    };
  },

  computed: {
    selectedDuties() {
      return this.dutyRecords.filter(d => d.selected);
    },

    selectedDutiesList() {
      return this.dutyRecords.filter(d => d.selected);
    },

    selectedFormatName() {
      const format = this.exportFormats.find(f => f.type === this.selectedFormat);
      return format ? format.name : '';
    }
  },

  watch: {
    dutyRecords: {
      handler() {
        const allSelected = this.dutyRecords.length > 0 && this.dutyRecords.every(d => d.selected);
        this.selectAll = allSelected;
      },
      deep: true
    }
  },

  methods: {
    // 获取状态标签类型
    getStatusType(status) {
      const typeMap = {
        '已完成': 'success',
        '值班中': 'warning',
        '待值班': 'info'
      };
      return typeMap[status] || 'info';
    },

    // 全选/取消全选
    handleSelectAll(value) {
      this.dutyRecords.forEach(duty => {
        duty.selected = value;
      });
    },

    // 切换值班记录选择
    toggleDuty(dutyId) {
      const duty = this.dutyRecords.find(d => d.id === dutyId);
      if (duty) {
        duty.selected = !duty.selected;
      }
    },

    // 获取格式颜色
    getFormatColor(format) {
      const colorMap = {
        'Excel': '#67C23A',
        'PDF': '#E6A23C',
        'Word': '#409EFF',
        'Text': '#909399'
      };
      return colorMap[format] || '#909399';
    },

    // 获取格式图标
    getFormatIcon(format) {
      const iconMap = {
        'Excel': 'el-icon-s-grid',
        'PDF': 'el-icon-document',
        'Word': 'el-icon-edit-outline',
        'Text': 'el-icon-tickets'
      };
      return iconMap[format] || 'el-icon-document';
    },

    // 处理导出
    handleExport() {
      if (this.selectedDuties.length === 0) {
        this.showToast('请先选择要导出的值班信息', 'warning');
        return;
      }
      if (this.selectedFields.length === 0) {
        this.showToast('请至少选择一个导出字段', 'warning');
        return;
      }
      this.showExportDialog = true;
    },

    // 确认导出
    confirmExport() {
      this.showExportDialog = false;
      const loading = this.$loading({
        lock: true,
        text: '正在导出，请稍候...',
        background: 'rgba(0, 0, 0, 0.7)'
      });

      const selectedIds = this.selectedDuties.map(d => d.id);
      const exportParams = {
        format: this.selectedFormat,
        fields: this.selectedFields,
        options: this.exportOptions
      };

      // 如果只有一条记录，使用单个导出
      if (selectedIds.length === 1) {
        exportDutyInfo(selectedIds[0], exportParams)
          .then((result) => {
            loading.close();
            this.$notify({
              title: '✅ 导出成功',
              message: `值班信息已导出为 ${result.fileName}`,
              type: 'success',
              duration: 3000,
              position: 'top-right',
              offset: 60
            });
            this.loadExportHistory();
            // 模拟下载
            this.simulateDownload(result.downloadUrl, result.fileName);
          })
          .catch(error => {
            loading.close();
            this.showToast(error.message || '导出失败', 'error');
          });
      } else {
        // 批量导出
        batchExportDutyInfo(selectedIds, exportParams)
          .then((result) => {
            loading.close();
            this.$notify({
              title: '✅ 导出成功',
              message: `${result.count} 条值班信息已打包导出`,
              type: 'success',
              duration: 3000,
              position: 'top-right',
              offset: 60
            });
            this.loadExportHistory();
            // 模拟下载
            this.simulateDownload(result.downloadUrl, result.fileName);
          })
          .catch(error => {
            loading.close();
            this.showToast(error.message || '导出失败', 'error');
          });
      }
    },

    // 生成文件内容
    generateFileContent(duties, format) {
      if (format === 'Text') {
        return this.generateTextContent(duties);
      } else if (format === 'Excel') {
        return this.generateExcelContent(duties);
      } else if (format === 'Word') {
        return this.generateWordContent(duties);
      } else if (format === 'PDF') {
        return this.generatePDFContent(duties);
      }
      return '';
    },

    // 生成文本内容
    generateTextContent(duties) {
      let content = '值班信息导出报告\n';
      content += '='.repeat(60) + '\n\n';
      content += `导出时间：${new Date().toLocaleString('zh-CN')}\n`;
      content += `导出记录数：${duties.length} 条\n\n`;
      content += '='.repeat(60) + '\n\n';

      duties.forEach((duty, index) => {
        content += `【记录 ${index + 1}】\n`;
        content += `-`.repeat(60) + '\n';
        
        if (this.selectedFields.includes('dutyPerson')) {
          content += `值班人员：${duty.dutyPerson}\n`;
        }
        if (this.selectedFields.includes('dutyDate')) {
          content += `值班日期：${duty.dutyDate}\n`;
        }
        if (this.selectedFields.includes('shift')) {
          content += `值班班次：${duty.shift}\n`;
        }
        if (this.selectedFields.includes('location')) {
          content += `值班地点：${duty.location}\n`;
        }
        if (this.selectedFields.includes('department')) {
          content += `所属部门：${duty.department}\n`;
        }
        if (this.selectedFields.includes('phone') && this.exportOptions.includeContact) {
          content += `联系电话：${duty.phone}\n`;
        }
        if (this.selectedFields.includes('emergencyContact') && this.exportOptions.includeContact) {
          content += `紧急联系人：${duty.emergencyContact}\n`;
        }
        if (this.selectedFields.includes('duties')) {
          content += `主要职责：${duty.duties}\n`;
        }
        if (this.selectedFields.includes('events')) {
          content += `处理事件：${duty.events || '无'}\n`;
        }
        if (this.selectedFields.includes('remark') && this.exportOptions.includeRemark) {
          content += `备注信息：${duty.remark || '无'}\n`;
        }
        
        content += `\n`;
      });

      content += '='.repeat(60) + '\n';
      content += '报告结束\n';
      
      return content;
    },

    // 生成Excel内容（CSV格式）
    generateExcelContent(duties) {
      let content = '\uFEFF'; // UTF-8 BOM for Excel
      
      // 表头
      const headers = [];
      const fieldMap = {
        'dutyPerson': '值班人员',
        'dutyDate': '值班日期',
        'shift': '值班班次',
        'location': '值班地点',
        'department': '所属部门',
        'phone': '联系电话',
        'emergencyContact': '紧急联系人',
        'duties': '主要职责',
        'events': '处理事件',
        'remark': '备注信息'
      };
      
      this.selectedFields.forEach(field => {
        if (field === 'phone' || field === 'emergencyContact') {
          if (this.exportOptions.includeContact) {
            headers.push(fieldMap[field]);
          }
        } else if (field === 'remark') {
          if (this.exportOptions.includeRemark) {
            headers.push(fieldMap[field]);
          }
        } else {
          headers.push(fieldMap[field]);
        }
      });
      
      content += headers.join(',') + '\n';
      
      // 数据行
      duties.forEach(duty => {
        const row = [];
        this.selectedFields.forEach(field => {
          if (field === 'phone' || field === 'emergencyContact') {
            if (this.exportOptions.includeContact) {
              row.push(`"${(duty[field] || '').replace(/"/g, '""')}"`);
            }
          } else if (field === 'remark') {
            if (this.exportOptions.includeRemark) {
              row.push(`"${(duty[field] || '无').replace(/"/g, '""')}"`);
            }
          } else {
            row.push(`"${(duty[field] || '无').replace(/"/g, '""')}"`);
          }
        });
        content += row.join(',') + '\n';
      });
      
      return content;
    },

    // 生成Word内容（HTML格式）
    generateWordContent(duties) {
      let html = `
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style>
    body { font-family: "Microsoft YaHei", Arial, sans-serif; padding: 20px; }
    h1 { text-align: center; color: #333; border-bottom: 2px solid #409EFF; padding-bottom: 10px; }
    .info { margin: 20px 0; padding: 10px; background: #f5f5f5; }
    table { width: 100%; border-collapse: collapse; margin: 20px 0; }
    th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }
    th { background-color: #409EFF; color: white; font-weight: bold; }
    tr:nth-child(even) { background-color: #f9f9f9; }
    .footer { margin-top: 30px; text-align: center; color: #999; font-size: 12px; }
  </style>
</head>
<body>
  <h1>值班信息导出报告</h1>
  <div class="info">
    <p><strong>导出时间：</strong>${new Date().toLocaleString('zh-CN')}</p>
    <p><strong>导出记录数：</strong>${duties.length} 条</p>
    <p><strong>导出格式：</strong>Word文档</p>
  </div>
  
  <table>
    <thead>
      <tr>
`;
      
      const fieldMap = {
        'dutyPerson': '值班人员',
        'dutyDate': '值班日期',
        'shift': '值班班次',
        'location': '值班地点',
        'department': '所属部门',
        'phone': '联系电话',
        'emergencyContact': '紧急联系人',
        'duties': '主要职责',
        'events': '处理事件',
        'remark': '备注信息'
      };
      
      this.selectedFields.forEach(field => {
        if (field === 'phone' || field === 'emergencyContact') {
          if (this.exportOptions.includeContact) {
            html += `        <th>${fieldMap[field]}</th>\n`;
          }
        } else if (field === 'remark') {
          if (this.exportOptions.includeRemark) {
            html += `        <th>${fieldMap[field]}</th>\n`;
          }
        } else {
          html += `        <th>${fieldMap[field]}</th>\n`;
        }
      });
      
      html += `      </tr>
    </thead>
    <tbody>
`;
      
      duties.forEach(duty => {
        html += '      <tr>\n';
        this.selectedFields.forEach(field => {
          if (field === 'phone' || field === 'emergencyContact') {
            if (this.exportOptions.includeContact) {
              html += `        <td>${duty[field] || '无'}</td>\n`;
            }
          } else if (field === 'remark') {
            if (this.exportOptions.includeRemark) {
              html += `        <td>${duty[field] || '无'}</td>\n`;
            }
          } else {
            html += `        <td>${duty[field] || '无'}</td>\n`;
          }
        });
        html += '      </tr>\n';
      });
      
      html += `    </tbody>
  </table>
  
  <div class="footer">
    <p>本报告由应急值守系统自动生成</p>
  </div>
</body>
</html>
`;
      return html;
    },

    // 生成PDF内容（HTML格式）
    generatePDFContent(duties) {
      // PDF 和 Word 使用类似的 HTML 格式
      return this.generateWordContent(duties);
    },

    // 实际文件下载
    simulateDownload(url, fileName) {
      try {
        // 获取选中的值班记录
        const selectedDuties = this.dutyRecords.filter(d => d.selected);
        
        // 生成文件内容
        const content = this.generateFileContent(selectedDuties, this.selectedFormat);
        
        // 确定MIME类型
        let mimeType = 'text/plain';
        if (this.selectedFormat === 'Excel') {
          mimeType = 'text/csv';
        } else if (this.selectedFormat === 'Word') {
          mimeType = 'application/msword';
        } else if (this.selectedFormat === 'PDF') {
          mimeType = 'text/html';
        }
        
        // 创建Blob对象
        const blob = new Blob([content], { type: mimeType });
        
        // 创建下载链接
        const downloadUrl = window.URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.href = downloadUrl;
        link.download = fileName;
        
        // 触发下载
        document.body.appendChild(link);
        link.click();
        
        // 清理
        document.body.removeChild(link);
        window.URL.revokeObjectURL(downloadUrl);
        
        // this.showToast('文件下载已开始');
      } catch (error) {
        console.error('下载失败:', error);
        this.showToast('文件下载失败，请重试', 'error');
      }
    },

    // 下载历史文件
    downloadFile(record) {
      this.showToast(`正在准备下载 ${record.fileName}`);
      
      // 对于历史记录，我们生成一个示例文件
      setTimeout(() => {
        try {
          const content = `值班信息历史导出文件\n\n文件名：${record.fileName}\n导出时间：${record.exportTime}\n文件大小：${record.fileSize}\n记录数：${record.recordCount}\n\n这是一个历史导出文件的示例内容。\n实际项目中，这里应该从服务器获取真实的文件内容。`;
          
          const blob = new Blob([content], { type: 'text/plain' });
          const downloadUrl = window.URL.createObjectURL(blob);
          const link = document.createElement('a');
          link.href = downloadUrl;
          link.download = record.fileName;
          
          document.body.appendChild(link);
          link.click();
          
          document.body.removeChild(link);
          window.URL.revokeObjectURL(downloadUrl);
          
          this.showToast('文件下载已开始');
        } catch (error) {
          console.error('下载失败:', error);
          this.showToast('文件下载失败，请重试', 'error');
        }
      }, 500);
    },

    // Toast提示
    showToast(message, type = 'success') {
      this.$notify({
        title: '',
        message: message,
        type: type,
        duration: 2000,
        position: 'top-right',
        offset: 60
      });
    },

    // 加载值班记录列表
    loadDutyRecords() {
      const loading = this.$loading({
        lock: true,
        text: '加载中...',
        background: 'rgba(0, 0, 0, 0.7)'
      });

      getDutyRecords().then(data => {
        this.dutyRecords = data.map(d => ({
          ...d,
          selected: false
        }));
        loading.close();
      }).catch(error => {
        loading.close();
        this.showToast(error.message || '加载失败', 'error');
      });
    },

    // 加载导出历史
    loadExportHistory() {
      getExportHistory().then(data => {
        this.exportHistory = data;
      }).catch(error => {
        console.error('加载导出历史失败', error);
      });
    }
  },

  mounted() {
    this.loadDutyRecords();
    this.loadExportHistory();
  }
};
</script>

<style scoped>
.duty-export {
  background: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 80px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* 值班信息选择 */
.duty-select-section {
  background: white;
  margin-bottom: 10px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.section-header {
  display: flex;
  align-items: center;
  padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-size: 16px;
  font-weight: 600;
}

.section-header i {
  font-size: 20px;
  margin-right: 8px;
}

.select-all-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 15px;
  background: #f8f9fa;
  border-bottom: 1px solid #e4e7ed;
}

.select-count {
  font-size: 13px;
  color: #666;
}

.duty-list {
  padding: 10px 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 400px;
  overflow-y: auto;
}

.duty-item {
  display: flex;
  align-items: flex-start;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  transition: all 0.3s;
}

.duty-item >>> .el-checkbox {
  margin-right: 12px;
  margin-top: 2px;
  flex-shrink: 0;
}

.duty-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.duty-info:active {
  opacity: 0.7;
}

.duty-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.duty-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  flex: 1;
  margin-right: 8px;
}

.duty-meta {
  display: flex;
  align-items: center;
  gap: 15px;
  font-size: 12px;
  color: #666;
  margin-top: 5px;
}

.duty-meta i {
  margin-right: 3px;
  color: #409EFF;
}

/* 字段选择 */
.field-select-section {
  background: white;
  margin-bottom: 10px;
  padding: 15px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.section-title {
  display: flex;
  align-items: center;
  font-size: 15px;
  font-weight: 600;
  color: #333;
  margin-bottom: 12px;
}

.section-title i {
  font-size: 18px;
  margin-right: 6px;
  color: #409EFF;
}

.field-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-item {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 10px 12px;
}

.field-item >>> .el-checkbox {
  display: flex;
  align-items: center;
}

.field-label {
  display: flex;
  align-items: center;
  font-size: 14px;
}

.field-label i {
  font-size: 16px;
  margin-right: 6px;
  color: #409EFF;
}

/* 导出格式选择 */
.export-format-section {
  background: white;
  margin-bottom: 10px;
  padding: 15px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.format-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.format-card {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 20px 15px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.format-card.active {
  background: #e7f4ff;
  border-color: #409EFF;
}

.format-card:active {
  transform: scale(0.95);
}

.format-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.format-icon i {
  font-size: 24px;
  color: white;
}

.format-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 5px;
}

.format-desc {
  font-size: 12px;
  color: #999;
}

/* 导出选项 */
.export-options-section {
  background: white;
  margin-bottom: 10px;
  padding: 15px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.option-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
}

.option-label {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #333;
}

.option-label i {
  font-size: 18px;
  margin-right: 8px;
  color: #409EFF;
}

/* 导出历史 */
.export-history-section {
  background: white;
  margin-bottom: 10px;
  padding: 15px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  display: flex;
  align-items: center;
  background: #f8f9fa;
  border-radius: 8px;
  padding: 12px;
}

.history-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 12px;
}

.history-icon i {
  font-size: 20px;
  color: white;
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-detail {
  font-size: 12px;
  color: #999;
}

.separator {
  margin: 0 5px;
}

.history-action {
  margin-left: 10px;
  flex-shrink: 0;
}

/* 操作按钮 */
.action-buttons {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  padding: 15px;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  z-index: 100;
  border-top: 1px solid #f0f0f0;
}

.action-buttons .el-button {
  width: 100%;
  border-radius: 6px;
  font-size: 15px;
  height: 46px;
  font-weight: 500;
}

/* 导出确认对话框 */
.export-confirm-content {
  padding: 10px 0;
}

.confirm-info {
  display: flex;
  align-items: flex-start;
  padding: 15px;
  background: #f0f9ff;
  border-radius: 8px;
  margin-bottom: 15px;
}

.confirm-info i {
  font-size: 24px;
  color: #409EFF;
  margin-right: 12px;
  flex-shrink: 0;
}

.info-text {
  flex: 1;
}

.info-text p {
  margin: 5px 0;
  font-size: 14px;
  color: #333;
}

.info-text strong {
  color: #409EFF;
  font-weight: 600;
}

.duty-summary {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 15px;
}

.summary-title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 10px;
}

.summary-list {
  max-height: 300px;
  overflow-y: auto;
}

.summary-item {
  display: flex;
  align-items: flex-start;
  padding: 8px 0;
  font-size: 13px;
  color: #666;
}

.item-index {
  margin-right: 8px;
  color: #999;
  flex-shrink: 0;
}

.item-title {
  flex: 1;
  line-height: 1.4;
}

.dialog-footer {
  display: flex;
  gap: 10px;
  padding: 0;
}

.dialog-footer .el-button {
  flex: 1;
  margin: 0;
}
</style>

